package de.e2it3t.schulverwaltung.data;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * Objektmodell für die View "lehrblock_view".
 *
 * @author Markus Kunz und Viktor Reiser
 */
@JdbcEntity
public class LehrblockTable extends Lehrblock {
   
    private static SimpleDateFormat sdfWeek =
            new SimpleDateFormat("ww", Locale.GERMANY);
    private static SimpleDateFormat sdfDate =
            new SimpleDateFormat("d. MMM ", Locale.GERMANY);
    
    
    @JdbcColumn(name = "bezeichnung", ignorePersist=true)
    private String klasse;
    
    private String kalenderwocheString;
    
    
    public String getKlasse() {
        return klasse;
    }
    
    public void buildKalenderwocheString() {
        Calendar cal = new GregorianCalendar(Locale.GERMANY);
        
        cal.clear();
        cal.set(Calendar.YEAR, getJahr());
        cal.set(Calendar.WEEK_OF_YEAR, getKalenderwoche());
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        
        StringBuilder sb = new StringBuilder();
        sb.append("KW ");
        sb.append(sdfWeek.format(cal.getTime()));
        sb.append(" | ");
        sb.append(sdfDate.format(cal.getTime()));
        sb.append(" - ");
        
        cal.add(Calendar.DATE, 6);
        sb.append(sdfDate.format(cal.getTime()));
        
        kalenderwocheString = sb.toString();
    }
}
